using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.IO;

namespace G2007.CodeGen.Library.DataProfessional
{
    [Serializable]
    public class ApplicationConfig
    {


        public static ApplicationConfig LoadAppConfig(string commonAppPath)
        {
            string configFileLocation=commonAppPath + "\\" +
                System.Configuration.ConfigurationSettings.AppSettings["ConfigFile"];

            ApplicationConfig appConfig;

            if (File.Exists(configFileLocation))
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(configFileLocation);

                Exception exception;

                appConfig = (ApplicationConfig)
                    Kellogs.SerialUtils.GetObject(xmlDoc , typeof(ApplicationConfig) , out exception);

                if (exception != null) return new ApplicationConfig();
            }
            else
            {
                return new ApplicationConfig();
            }


            return appConfig;
            
        }

        public static bool SaveAppConfig(ApplicationConfig appConfig, string commonAppPath)
        {
            string configFileLocation=commonAppPath + "\\" +
                System.Configuration.ConfigurationSettings.AppSettings["ConfigFile"];

            Kellogs.SerialUtils.GetObject(typeof(ApplicationConfig) , appConfig).Save(configFileLocation);

            return true;
        }



        private SimpleType[] simpleTypes=new SimpleType[0];

        public SimpleType[] SimpleTypes
        {
            get { return simpleTypes; }
            set { simpleTypes = value; }
        }

        private Transform[] transforms = new Transform[0];

        public Transform[] Transforms
        {
            get { return transforms; }
            set { transforms = value; }
        }
	



        
	
        [Serializable]
        public class Transform
        {

            public override string ToString()
            {
                return configName;
            }

            private string directory;

            public string Directory
            {
                get { return directory; }
                set { directory = value; }
            }


            // i.e. .NET 1.1 Packaged
            private string configName;

            public string ConfigName
            {
                get { return configName; }
                set { configName = value; }
            }



            private Generator[] classGenerators = new Generator[0];

            public Generator[] ClassGenerators
            {
                get { return classGenerators; }
                set { classGenerators = value; }
            }

            private Generator[] enumGenerators = new Generator[0];

            public Generator[] EnumGenerators
            {
                get { return enumGenerators; }
                set { enumGenerators = value; }
            }

            private Generator[] headerGenerators = new Generator[0];

            public Generator[] HeaderGenerators
            {
                get { return headerGenerators; }
                set { headerGenerators = value; }
            }

            private Generator[] sysGenerators = new Generator[0];

            public Generator[] SysGenerators
            {
                get { return sysGenerators; }
                set { sysGenerators = value; }
            }


            private Generator[] headerAndClassGenerators = new Generator[0];

            public Generator[] HeaderAndClassGenerators
            {
                get { return headerAndClassGenerators; }
                set { headerAndClassGenerators = value; }
            }
	
	


            [Serializable]
            public class Generator
            {
                public override string ToString()
                {
                    return name;
                }

                private string name;

                public string Name
                {
                    get { return name; }
                    set { name = value; }
                }

                private string filename;

                public string Filename
                {
                    get { return filename; }
                    set { filename = value; }
                }
	

                private string outputTransform;

                public string OutputTransform
                {
                    get { return outputTransform; }
                    set { outputTransform = value; }
                }
	
	
            }
	
        }


        public SimpleType GetSimpleTypeByType(string type)
        {
            foreach (SimpleType st in this.simpleTypes)
            {
                if (st.Name.Equals(type)) return st;
            }
            return new SimpleType();
        }


        [Serializable]
        public class SimpleType
        {

            public override string ToString()
            {
                return name;
            }

            private string gaModule;

            public string GAModule
            {
                get { return gaModule; }
                set { gaModule = value; }
            }
	

            private string tsqlAccessor;

            public string TSQLAccessor
            {
                get { return tsqlAccessor; }
                set { tsqlAccessor = value; }
            }
	

            private string sqlType;

            public string SQLType
            {
                get { return sqlType; }
                set { sqlType = value; }
            }
	

            private string sqlAccessor;

            public string SQLAccessor
            {
                get { return sqlAccessor; }
                set { sqlAccessor = value; }
            }
	

            private string name;

            public string Name
            {
                get { return name; }
                set { name = value; }
            }
	

        }
    }
}
